package com.xydtech.ecard.config.controller;

import com.xydtech.common.annotation.Log;
import com.xydtech.common.core.controller.BaseController;
import com.xydtech.common.core.domain.AjaxResult;
import com.xydtech.common.core.page.TableDataInfo;
import com.xydtech.common.enums.BusinessType;
import com.xydtech.common.utils.poi.ExcelUtilMap;
import com.xydtech.ecard.config.domain.EcardBusiReportPublic;
import com.xydtech.ecard.config.service.IEcardBusiReportPublicService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.LinkedHashMap;
import java.util.List;

/**
 * 电子名片业务填报对公类信息Controller
 *
 * @author xydtech
 * @date 2024-09-29
 */
@Controller
@RequestMapping("/ecard/config/busiReportPublic")
public class EcardBusiReportPublicController extends BaseController
{
    private String prefix = "ecard/config/busiReportPublic";

    @Autowired
    private IEcardBusiReportPublicService ecardBusiReportPublicService;

    @RequiresPermissions("ecard:config:busiReportPublic:view")
    @GetMapping()
    public String busiReportPublic()
    {
        return prefix + "/busiReportPublic";
    }

    /**
     * 查询电子名片业务填报对公类信息列表
     */
    @RequiresPermissions("ecard:config:busiReportPublic:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EcardBusiReportPublic ecardBusiReportPublic)
    {
        String salt = getSalt();//盐值
        startPage();
        List<EcardBusiReportPublic> list = ecardBusiReportPublicService.selectEcardBusiReportPublicList(ecardBusiReportPublic, salt);
        return getDataTable(list);
    }

    /**
     * 导出电子名片业务填报对公类信息列表
     */
    @RequiresPermissions("ecard:config:busiReportPublic:export")
    @Log(title = "电子名片业务填报对公类信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EcardBusiReportPublic ecardBusiReportPublic)
    {
        String salt = getSalt();//盐值
        List<LinkedHashMap<String, Object>> list = ecardBusiReportPublicService.selectEcardBusiReportPublicListByExport(ecardBusiReportPublic, salt);
        return ExcelUtilMap.getInstance().createExcel(list, "电子名片业务填报对公类信息", "电子名片业务填报对公类信息");
    }

    /**
     * 新增电子名片业务填报对公类信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存电子名片业务填报对公类信息
     */
    @RequiresPermissions("ecard:config:busiReportPublic:add")
    @Log(title = "电子名片业务填报对公类信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EcardBusiReportPublic ecardBusiReportPublic)
    {
        String salt = getSalt();//盐值
        return toAjax(ecardBusiReportPublicService.insertEcardBusiReportPublic(ecardBusiReportPublic, salt));
    }

    /**
     * 修改电子名片业务填报对公类信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        String salt = getSalt();//盐值
        EcardBusiReportPublic ecardBusiReportPublic = ecardBusiReportPublicService.selectEcardBusiReportPublicById(id, salt);
        mmap.put("ecardBusiReportPublic", ecardBusiReportPublic);
        return prefix + "/edit";
    }

    /**
     * 修改保存电子名片业务填报对公类信息
     */
    @RequiresPermissions("ecard:config:busiReportPublic:edit")
    @Log(title = "电子名片业务填报对公类信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EcardBusiReportPublic ecardBusiReportPublic)
    {
        String salt = getSalt();//盐值
        return toAjax(ecardBusiReportPublicService.updateEcardBusiReportPublic(ecardBusiReportPublic, salt));
    }

    /**
     * 删除电子名片业务填报对公类信息
     */
    @RequiresPermissions("ecard:config:busiReportPublic:remove")
    @Log(title = "电子名片业务填报对公类信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ecardBusiReportPublicService.deleteEcardBusiReportPublicByIds(ids));
    }
}
